package com.tuoyu.peopletest.view.pop;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.lxj.xpopup.core.CenterPopupView;
import com.tuoyu.peopletest.R;
import com.tuoyu.peopletest.entity.DataBean;
import com.tuoyu.peopletest.scinterface.OnDataListener;
import com.tuoyu.peopletest.utils.SCUIUtils;
import com.tuoyu.peopletest.utils.SCUtils;

import androidx.annotation.NonNull;

/**
 * 带输入的dialog
 */
public class TestDetailDialog extends CenterPopupView implements View.OnClickListener {


    private DataBean dataBean;
    private EditText etInput;
    private OnDataListener<String> listener;

    public TestDetailDialog(@NonNull Context context, DataBean dataBean) {
        super(context);
        this.dataBean = dataBean;
    }


    @Override
    protected int getImplLayoutId() {

        return R.layout.dialog_test_detail;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        if(dataBean == null){
            return;
        }
        TextView tvProject = findViewById(R.id.tv_project);
        tvProject.setText(SCUtils.getNoEmpty(dataBean.project));

        ((TextView)findViewById(R.id.tv_number)).setText(SCUtils.getNoEmpty(dataBean.number));
        ((TextView)findViewById(R.id.tv_area1)).setText(SCUtils.getNoEmpty(dataBean.area1));
        ((TextView)findViewById(R.id.tv_area2)).setText(SCUtils.getNoEmpty(dataBean.area2));
        if(dataBean.jtj_or_yg.equals("1")){
            ((TextView)findViewById(R.id.tv_select)).setText("胶体金");
        }else {
            ((TextView)findViewById(R.id.tv_select)).setText("荧光");
        }

        //亮度
        ((TextView)findViewById(R.id.tv_area2)).setText(SCUtils.getNoEmpty(dataBean.area2));
        ((TextView)findViewById(R.id.tv_brightness)).setText(SCUtils.getNoEmpty(dataBean.brightness));
        ((TextView)findViewById(R.id.tv_ad)).setText(SCUtils.getNoEmpty(dataBean.ad));
        ((TextView)findViewById(R.id.tv_start)).setText(SCUtils.getNoEmpty(dataBean.start));
        ((TextView)findViewById(R.id.tv_stop)).setText(SCUtils.getNoEmpty(dataBean.stop));
        ((TextView)findViewById(R.id.tv_step)).setText(SCUtils.getNoEmpty(dataBean.step));
        ((TextView)findViewById(R.id.tv_waveLength)).setText(SCUtils.getNoEmpty(dataBean.waveLength));
        ((TextView)findViewById(R.id.tv_time)).setText(SCUtils.getNoEmpty(dataBean.create_time));

        findViewById(R.id.tv_btn_cancle).setOnClickListener(this);
    }

    @Override
    protected void onShow() {
        super.onShow();
    }

    @Override
    protected void onDismiss() {
        super.onDismiss();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_btn_cancle:
                dismiss();
                break;
        }
    }

    public void setEdStr(String nickname) {
        etInput.setText(SCUtils.getNoEmpty(nickname));
        if(!TextUtils.isEmpty(nickname)){
            etInput.setSelection(nickname.length());
        }
    }

    public void setDataListener(OnDataListener<String> listener) {
        this.listener = listener;
    }

}
